import Explorer.config as G

from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render

from Utils.utils import Controller
from Explorer.user import *
from Explorer.explorer import *

def static_cry(request,path):
    return HttpResponseRedirect('/static/'+path)
def test(request):
    return Controller.show_json({"re":"re"})

def index(request):
    path,default,state= Controller.get_data_base_dir()
    if not state:
        return HttpResponseRedirect('/')
    context ={
        "config":G.CONFIG,
        "user":G.USERINFO,
        "LNG":G.LNG,
        "b":2,
        "title":"title"
    }
    return render(request,'Explorer/index.html',context )

def indexphp(request):
    req = request.GET

    if (req.__contains__("user/commonJs")):
        user = User()
        return user.commonJs(request,req['st'],req['act'])
    explorer = Explorer()
    if(req.__contains__("explorer/pathList")):
        return explorer.pathlist(req['path'])


    if (req.__contains__("explorer/image")):
        return explorer.image(request,req['path'],req['time'])

    build = {
        "explorer/pathInfo":"pathInfo"
        ,"explorer/search":"search"
        ,"explorer/mkdir":"mkdir"
        ,"explorer/mkfile":"mkfile"
        ,"explorer/pathDelete":"pathDelete"
        ,"explorer/pathRname":"rname"
        ,"explorer/treeList":"treelist"
        ,"explorer/pathCopy":"pathCopy"
        ,"explorer/pathCuteDrag":"pathCutDrag"
        ,"explorer/pathCute":"pathCut"
        ,"explorer/pathPast":"pathPaste"

    }
    for key in build:
        if (req.__contains__(key)):
            fun = explorer.__getattribute__(build[key])
            return fun(request)

    return Controller.show_json({"remark": "not match", "GET": req,"POST":request.POST},False)




